{#

This file is part of the Sonata package.

(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{% extends sonata_block.templates.block_base %}

{% set translation_domain = settings.translation_domain ?? admin.translationDomain %}

{% block block %}
    {% set inlineAnchor = settings.text|replace({'.':'_'}) %}
    {% set results_count = admin.datagrid.pager.countResults %}
    <div class="box box-primary" id="{{ inlineAnchor }}">
        <div class="box-header with-border">
            {{ settings.icon|default('')|parse_icon }}
            <h3 class="box-title">
                <a href="#{{ inlineAnchor }}">
                    {% if translation_domain is same as(false) %}
                        {{ settings.text }}
                    {% else %}
                        {{ settings.text|trans({}, translation_domain) }}
                    {% endif %}
                </a>
            </h3>
        </div>
        <div class="box-body {% if results_count > 0 %}table-responsive no-padding{% endif %}">
            {{ sonata_block_render_event('sonata.admin.list.table.top', { 'admin': admin }) }}

            {% block list_header %}{% endblock %}

            {% if results_count > 0 %}
                <table class="table table-bordered table-striped table-hover sonata-ba-list">
                    {% block table_header %}
                        <thead>
                            <tr class="sonata-ba-list-field-header">
                                {% for field_description in admin.list.getElements() %}
                                    {% if field_description.name == constant('Sonata\\AdminBundle\\Datagrid\\ListMapper::NAME_SELECT') %}
                                        <th class="sonata-ba-list-field-header sonata-ba-list-field-header-select"></th>
                                    {% else %}
                                        <th class="sonata-ba-list-field-header-{{ field_description.type}} {% if field_description.option('header_class') is not null %} {{ field_description.option('header_class') }}{% endif %}"{% if field_description.option('header_style') is not null %} style="{{ field_description.option('header_style') }}"{% endif %}>
                                            {% if field_description.option('label_icon') %}
                                                <span class="sonata-ba-list-field-header-label-icon">
                                                        {{ field_description.option('label_icon')|parse_icon }}
                                                    </span>
                                            {% endif %}
                                            {% if field_description.translationDomain is same as(false) %}
                                                {{ field_description.label }}
                                            {% else %}
                                                {{ field_description.label|trans({}, field_description.translationDomain) }}
                                            {% endif %}
                                        </th>
                                    {% endif %}
                                {% endfor %}
                            </tr>
                        </thead>
                    {% endblock %}

                    {% block table_body %}
                        <tbody>
                            {% include get_admin_template('outer_list_rows_' ~ admin.getListMode(), admin.code) %}
                        </tbody>
                    {% endblock %}

                    {% block table_footer %}
                    {% endblock %}
                </table>
                <div class="box-footer">
                    {% if admin.hasAccess('list') %}
                        <a href="{{ admin.generateUrl('list', {filter: settings.filters}) }}" class="btn btn-primary btn-block">
                            <i class="fas fa-list" aria-hidden="true"></i> {{ 'preview_view_more'|trans({}, 'SonataAdminBundle') }}
                        </a>
                    {% endif %}
                </div>
            {% else %}
                {% block no_result_content %}
                    <div class="info-box">
                        <div class="info-box">
                            <span class="info-box-text">{{ 'no_result'|trans({}, 'SonataAdminBundle') }}</span>
                        </div><!-- /.info-box-content -->
                    </div>
                {% endblock %}
            {% endif %}

            {{ sonata_block_render_event('sonata.admin.list.table.bottom', { 'admin': admin }) }}
        </div>
    </div>
{% endblock %}
